package com.baymax.test.scene

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.junit.Test

class MapTest {

    @Test
    fun `test impl get or default`() {
        val r = toJsonMap(null)
        println(r::class)
        println(r.withDefault { "" }::class.java.interfaces.contentToString())
        val de = MapDelegate(r.withDefault { "" })
        println(de)
    }

    fun toJsonMap(string: String?): Map<String, String?> = Gson().fromJson<Map<String, String?>>(
        string,
        object : TypeToken<Map<String, String?>>() {}.type
    ).orEmpty()

    class MapDelegate(map: Map<String, String?>) {
        val testNoKey: String by map
        override fun toString(): String {
            return "MapDelegate(testNoKey='$testNoKey')"
        }


    }
}